package com.lazycoffee.lcloancalculator.components

import com.tencent.kuikly.core.base.Border
import com.tencent.kuikly.core.base.BorderStyle
import com.tencent.kuikly.core.base.Color
import com.tencent.kuikly.core.base.ComposeAttr
import com.tencent.kuikly.core.base.ComposeEvent
import com.tencent.kuikly.core.base.ComposeView
import com.tencent.kuikly.core.base.ViewBuilder
import com.tencent.kuikly.core.base.ViewContainer
import com.tencent.kuikly.core.views.Input

internal class FormInputAttr : ComposeAttr() {
    var inputPlaceholder: String = ""
    var isNumber: Boolean = false
}

internal class FormInputView : ComposeView<FormInputAttr, ComposeEvent>() {
    override fun createAttr(): FormInputAttr {
        return FormInputAttr()
    }

    override fun createEvent(): ComposeEvent {
        return ComposeEvent()
    }

    override fun body(): ViewBuilder {
        val ctx = this
        return {
            Input {
                attr {
                    color(Color.BLACK)
                    placeholder(ctx.attr.inputPlaceholder)
                    placeholderColor(Color(0,0,0,0.3F))
                    height(40F)
                    border(Border(1F, BorderStyle.SOLID, Color(0, 0, 0, 0.2F)))
                    borderRadius(3F)
                }
            }
        }
    }
}

internal fun ViewContainer<*, *>.FormInput(init: FormInputView.() -> Unit) {
    addChild(FormInputView(), init)
}